<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <title>后台首页</title>
    {load href="/static/css/admin.css" /}
</head>
<body>
<div class="head">
    <img src="/static/img/notify.svg"/>
    <span>欢迎使用小天科技商户云平台!</span>
    <span class="right">当前门店:<span class="green">{$Think.session.shopname}</span></span>
</div>

<div id="mycontent">
    <div class="searchbar">
        <form action="" method="get">
        <select name="ordstatus">
            <option value="">全部状态</option>
            <option value="1"{if condition="request()->get('ordstatus') eq 1"} selected{/if}>交易成功</option>
            <option value="2"{if condition="request()->get('ordstatus') eq 2"} selected{/if}>待支付</option>
            <option value="9"{if condition="request()->get('ordstatus') eq 9"} selected{/if}>待输入密码</option>
            <option value="4"{if condition="request()->get('ordstatus') eq 4"} selected{/if}>已取消</option>
        </select>
        <input type="date" name="sdate" placeholder="开始时间" value="{$Think.get.sdate}" readonly onclick="laydate()"/>
        <span style="margin-left: 15px;color: white;">—</span>
        <input type="date" name="edate" placeholder="结束时间"  value="{$Think.get.edate}" readonly onclick="laydate()"/>
        <input type="text" name="ordersn" id="ordersn" value="{$Think.get.ordersn}" placeholder="订单号/平台交易号"/>
        <input type="submit" name="" value="搜索" />
            <button type="button" id="export">导出</button>
        </form>

    </div>

    <table id="mytable" align="center" border="1px" cellpadding="0" cellspacing="0">
        <tr align="middle"><th>交易时间</th><th>订单号</th><th>平台交易号</th><th>商户名称</th><th>付款时间</th><th>付款方式</th><th>原始金额</th><th>优惠金额</th><th>交易金额</th><th>交易类型</th><th>交易状态</th></tr>
        {volist name="res" id="v"}
        <tr align="middle">
            <td>{$v.ord_add_time}</td><td>{$v.ord_no}</td><td>{$v.original_ord_no}</td><td>{$v.shop_name}</td><td>{$v.ord_trade_pay_time}</td><td>{$v.pmt_name}</td><td>{:number_format($v['ord_original_amount']/100,2,".","")}</td><td>{:number_format($v['ord_discount_amount']/100,2,".","")}</td><td>{:number_format($v['ord_trade_amount']/100,2,".","")}</td><td>{:getordtype($v['ord_type'])}</td><td>{:getordstatus($v['ord_status'])}</td>
        </tr>
        {/volist}
    </table>

    <div id="myfoot">
        <span>首页</span><span>上一页</span><span class="active">1</span><span>2</span><span>3</span><span>下一页</span>
    </div>
</div>
{load href="/static/js/laypage/laypage.js,/static/js/laydate/laydate.js" /}
<script>
    //好像很实用的样子，后端的同学再也不用写分页逻辑了。
    laypage({
            cont: 'myfoot',
            pages: {$totalpage}, //可以叫服务端把总页数放在某一个隐藏域，再获取。假设我们获取到的是18
        curr: function(){ //通过url获取当前页，也可以同上（pages）方式获取
        var page = location.search.match(/page=(\d+)/);
        return page ? page[1] : 1;
    }(),
        jump: function(e, first){ //触发分页后的回调
        if(!first){ //一定要加此判断，否则初始时会无限刷新
            location.href=setParam("page",e.curr);
        }
    }
    });
    //设置url中参数值
    function setParam(param,value){
        var query = location.search.substring(1);
        var p = new RegExp("(^|)" + param + "=([^&]*)(|$)");
        if(p.test(query)){
            //query = query.replace(p,"$1="+value);
            var firstParam=query.split(param)[0];
            var secondParam=query.split(param)[1];
            if(secondParam.indexOf("&")>-1){
                var lastPraam=secondParam.split("&")[1];
                return  '?'+firstParam+'&'+param+'='+value+'&'+lastPraam;
            }else{
                if(firstParam){
                    return '?'+firstParam+''+param+'='+value;
                }else{
                    return '?'+param+'='+value;
                }
            }
        }else{
            if(query == ''){
                return '?'+param+'='+value;
            }else{
                return '?'+query+'&'+param+'='+value;
            }
        }
    }
    
    document.getElementById("export").addEventListener("click",function () {
        window.location.href="{:url('Index/exportdata')}"+window.location.search;
    })
</script>
</body>
</html>
